package com.yc.reflect;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class GeneratorImp<T> implements Generator<T> {


    @Override
    public T returnType() {
        Type genericSuperclass =
                this.getClass().getGenericSuperclass();

        Type[] actualTypeArguments = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
        Class<?> aClass = actualTypeArguments.getClass();
        try {
            return (T) aClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
